﻿using AugustSql;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        CellInfomationRepo cellInfomationRepo;
        StepRecipeBasicRepo stepRecipeBasicRepo;
        public MainWindow()
        {
            InitializeComponent(); 

            cellInfomationRepo = AugustOrmFactory.Register<CellInfomationRepo>("mytestDatabase");

            CellInfomation cellInfomation = cellInfomationRepo.GetElementOneSqlInformation(FirstOrLast.First, ["CellName"], ["yaoshun"]);



            bool ret = cellInfomationRepo.GetOne(out CellInfomation data, "www");

            //CellInfomation[] cellInfomations = cellInfomationRepo.GetElementSqlInformation(["CellType"], ["www"]);

            //stepRecipeBasicRepo = AugustOrmFactory.Register<StepRecipeBasicRepo>("mainframe");

            //StepRecipeBasic[] stepRecipeBasics =  stepRecipeBasicRepo.GetElementSqlInformation(["Name"], ["MyTest"]);

        }

        int keyIndex = 1;
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Task.Factory.StartNew(() =>
            {
                while (true)
                {

                    keyIndex++;
                    CellInfomation cellInfomation = cellInfomationRepo.CreateOne(DateTime.Now);
                    cellInfomation.CellName = "KeyName" + keyIndex;
                    cellInfomation.DateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    cellInfomation.CellType555 = "wo shi ni baba , can't ok" + keyIndex;
                    cellInfomation.SetSqlInformation();
                }

            }, TaskCreationOptions.LongRunning);

            Task.Factory.StartNew(() =>
            {
                while (true)
                {

                    keyIndex++;
                    CellInfomation cellInfomation = cellInfomationRepo.CreateOne(DateTime.Now);
                    cellInfomation.CellName = "KeyName" + keyIndex;
                    cellInfomation.DateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    cellInfomation.CellType555 = "wo shi ni baba" + keyIndex;
                    cellInfomation.SetSqlInformation();
                }

            }, TaskCreationOptions.LongRunning);

        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            //SqlInformationBase.InitMySqlInstatnce(sqlInformationCollection);
        }
    }
}